package cn.czg.cms.service.impl;

import cn.czg.cms.mapper.UserFollowMapper;
import cn.czg.cms.service.AuthService;
import cn.czg.cms.service.FollowService;
import org.springframework.stereotype.Service;

@Service
public class FollowServiceImpl implements FollowService {


    private final UserFollowMapper userFollowMapper;

    private final AuthService authService; // 获取当前登录用户ID

    public FollowServiceImpl(UserFollowMapper userFollowMapper, AuthService authService) {
        this.userFollowMapper = userFollowMapper;
        this.authService = authService;
    }

    @Override

    public void follow(Long followUserId) {
        Long userId = authService.getLoginUserId();
        userFollowMapper.insertFollow(userId, followUserId);
    }

    @Override

    public void unfollow(Long followUserId) {
        Long userId = authService.getLoginUserId();
        userFollowMapper.deleteFollow(userId, followUserId);
    }

    @Override

    public boolean isFollowing(Long followUserId) {
        Long userId = authService.getLoginUserId();
        return userFollowMapper.countFollow(userId, followUserId) > 0;
    }
}